<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%

request.setCharacterEncoding("utf-8");

String strAction = request.getParameter("action");
String strCatalogid = request.getParameter("catalogid");


String catalogname = request.getParameter("catalogname");
String strclassid = request.getParameter("classid");
String photos = request.getParameter("photos");
String about = request.getParameter("editorValue");

///判空操作//////////
if(null == catalogname || "".equals(catalogname)){
	out.println("标题不能为空");
}
//////////


com.zipishu.DataBaseConnection db = new com.zipishu.DataBaseConnection();
Connection con = db.getConnection();


String sql = "";

if("delete".equals(strAction)){
	sql = "DELETE FROM catelog WHERE catalogid=?";
	Integer catalogid = Integer.parseInt(strCatalogid);
	PreparedStatement pstmt = con.prepareStatement(sql);
	pstmt.setInt(1, catalogid);
	pstmt.executeUpdate();
}else{

	int classid = Integer.parseInt(strclassid);

	if(null == strCatalogid ||"".equals(strCatalogid)){
		sql = "INSERT INTO catelog(catalogname,classid,photos,about,createdate,updatedate,fatheid) VALUES (?,?,?,?,getdate(),getdate(),21212)";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1, catalogname);
		pstmt.setInt(2, classid);
		pstmt.setString(3, photos);
		pstmt.setString(4, about);	
		pstmt.executeUpdate();
	}else{
		Integer catalogid = Integer.parseInt(strCatalogid);
		sql = "UPDATE catelog SET catalogname=?,classid=?,photos=?,about=? WHERE catalogid=?";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1, catalogname);
		pstmt.setInt(2, classid);
		pstmt.setString(3, photos);
		pstmt.setString(4, about);	
		pstmt.setInt(5, catalogid);
		pstmt.executeUpdate();
	}
}
con.close();

response.sendRedirect("item.jsp");

%>
